package com.winit.project.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.winit.deploy.service.DeployService;
import com.winit.project.core.bean.EditionInfo;
import com.winit.project.core.bean.PackageTypeEnum;
import com.winit.project.core.bean.ProjectInfo;
import com.winit.project.manager.ProjectManager;
import com.winit.project.service.ProjectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by wangjian on 16/6/20.
 */
@Service
public class ProjectServiceImpl implements ProjectService {

    private static final Logger logger = LoggerFactory.getLogger(ProjectServiceImpl.class);

    @Autowired
    private ProjectManager projectManager;

    @Autowired
    private DeployService deployService;

    public List<ProjectInfo> getProjectList(String trunkName, PackageTypeEnum typeEnum, boolean onlyTrunk, boolean isShowJar) throws Exception {
        logger.info("获取工程信息列表,trunkName="+trunkName+",typeEnum="+typeEnum.getDesc()+",onlyTrunk="+onlyTrunk+",isShowJar="+isShowJar);
        if(!StringUtils.isEmpty(trunkName)){
            return projectManager.getProjectListByTrunkName(trunkName);
        }

        return projectManager.getProjectList(typeEnum,onlyTrunk,isShowJar);
    }

    public List<EditionInfo> getProjectEditionList(String projectName, boolean isShowAllE, boolean hasDefault) throws Exception{
        return projectManager.getProjectEditionList(projectName,isShowAllE,hasDefault);
    }

    public ProjectInfo getProjectInfo(String projectName) throws Exception{
        return projectManager.getProjectInfo(projectName);
    }

    public boolean isProjectExist(String projectName) throws Exception {
        return projectManager.isProjectExist(projectName);
    }

    public boolean isEditionExist(String projectName,String editionNum) throws Exception{
        return projectManager.isEditionExist(projectName,editionNum);
    }

    public JSONObject getPassProjectAndEdition(String trunkName) throws Exception{
        return deployService.getPassProjectAndEdition(trunkName);
    }
}
